package top.chmin.project.cloud.common.code.record.auto;

// field import auto

import cn.hutool.core.bean.BeanUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.chmin.project.cloud.common.entity.Page;


/**
 * chmin
 * 2023-12-27 15:50:14
 * cloud-builder
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class CodeRecordService {

    @Resource
    CodeRecordPlugin plugin;

    @Resource
    CodeRecordDao codeRecordDao;

// field labelDao auto

    public int save(CodeRecordSave.Param param) {
        plugin.checkSave(param);
        CodeRecord codeRecord = BeanUtil.toBean(param, CodeRecord.class);
        plugin.beforeSave(codeRecord);
        int result = codeRecordDao.save(codeRecord);
        plugin.afterSave(param, codeRecord, result);
        return result;
    }

    public int updateById(CodeRecordUpdateById.Param param) {
        plugin.checkUpdateById(param);
        CodeRecord codeRecord = BeanUtil.toBean(param, CodeRecord.class);
        plugin.beforeUpdateById(codeRecord);
        int result = codeRecordDao.updateById(codeRecord);
        plugin.afterUpdateById(param, codeRecord, result);
        return result;
    }

    public int deleteById(CodeRecordDeleteById.Param param) {
        plugin.checkDeleteById(param);
        int result = codeRecordDao.deleteById(param.getId());
        plugin.afterDeleteById(param, result);
        return result;
    }

    public CodeRecordSelectById.Result selectById(CodeRecordSelectById.Param param) {
        plugin.checkSelectById(param);
        CodeRecordFPC fpc = new CodeRecordFPC().id().eq(param.getId());
        plugin.beforeSelectById(param, fpc);
        CodeRecordSelectById.Result result = codeRecordDao.getFirst(fpc.toCondition(), CodeRecordSelectById.Result.class);
        plugin.afterSelectById(param, result);
        return result;
    }

    public Page<CodeRecordSelectPage.Result> selectPage(CodeRecordSelectPage.Param param) {
        plugin.checkSelectPage(param);
        CodeRecordFPC fpc = new CodeRecordFPC();
        fpc = param.isDesc() ? fpc.id().desc() : fpc.id().asc();
        plugin.beforeSelectPage(param, fpc);
        Page<CodeRecordSelectPage.Result> result = codeRecordDao.getPageByCondition(fpc.toCondition(), CodeRecordSelectPage.Result.class);
// field label auto
        plugin.afterSelectPage(param, result);
        return result;
    }

// entity select auto

// entity search auto

}
